# !/usr/bin/env python
# encoding: utf-8
# @File    : main_window_module.py
# @Time    : 2021/2/13
# @Author  : qiaowei
# @Version : 1.0
# @Email   : weiweiqiao@126.com
# @License : (C) Copyright 2013-2021
# @Brief   :


from PySide2.QtWidgets import QMainWindow
from PySide2.QtWidgets import QAction
from PySide2.QtCore import QObject
from PySide2.QtCore import SIGNAL
from PySide2.QtCore import SLOT
from PySide2.QtCore import QRegExp
from PySide2.QtGui import QRegExpValidator


from forms_package.mainwindow import Ui_MainWindow
from process_package.process_file_module import FileManager


class MainWindow(QMainWindow):
    """
    主窗体
    """
    def __init__(self, parent = None):
        QMainWindow.__init__(self, parent)

        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        self.__init_widgets()
        self.__init_instances()
        self.__init_connections()

    def __del__(self):
        # del self.manager
        pass

    def __init_instances(self):
        """
        实例化变量，执行用户的操作

        """
        self.manager = FileManager()

    def __init_widgets(self):
        """
        初始化窗体控件

        """
        # 设置菜单按钮
        self.file_menu_ = self.ui.menubar.addMenu('文件')
        self.open_file_action_ = QAction('打开文件', self)
        self.split_file_data_action_ = QAction('拆分数据', self)
        self.exit_application_action_ = QAction('退出', self)
        self.file_menu_.addAction(self.open_file_action_)
        self.file_menu_.addAction(self.split_file_data_action_)
        self.file_menu_.addAction(self.exit_application_action_)

        # 设置高度框取值范围及初始值
        self.ui.spin_box_max_altitude_.setRange(0, 15000)
        self.ui.spin_box_max_altitude_.setValue(13000)
        self.ui.spin_box_min_altitude_.setRange(0, 15000)
        self.ui.spin_box_min_altitude_.setValue(0)

        # 设置文本框的正则表达式，二次代码框输入数字，航班号输入字母和数字
        self.ui.edit_ssr_code_.setValidator(QRegExpValidator(QRegExp('[0-9]+$')))
        self.ui.edit_flight_number_.setValidator(QRegExpValidator(QRegExp('^[A-Za-z0-9]+$')))

    def __init_connections(self):
        self.split_file_data_action_.triggered.connect(self.manager.split_data_to_new_file)
        self.exit_application_action_.triggered.connect(self.manager.si_close_application)
